package com.shop.listener;

import com.shop.domain.Task;
import com.shop.service.TaskService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class Scheduling {
    @Autowired
    private TaskService taskService;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Scheduled(cron = "0 0/2 * * * ?")
    public void Scheduling(){
        List<Task> tasks = taskService.selectAll();
        if(tasks==null){
            return;
        }
        for (Task task : tasks) {
            rabbitTemplate.convertAndSend(task.getMqExchange(),task.getMqRoutingkey(),task.getRequestBody());
        }
    }
}
